package org.xy.yq.dao.impl;


import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.xy.yq.dao.IUserDao;
import org.xy.yq.entity.User;


import java.util.ArrayList;
import java.util.List;

@Repository("userDaoImpl")
public class UserDaoImpl implements IUserDao {
    @Autowired
    private SqlSessionTemplate sqlSession;
    @Override
    public void register(User user) {
        //2、执行操作
        sqlSession.getMapper(IUserDao.class).register(user);
    }
    @Override
    public User login(String username, String password) {
        User user =null;
        //2、执行操作
        user = sqlSession.getMapper(IUserDao.class).login(username,password);
        return user;
    }
    @Override
    public List<User> selectAll() {
        List<User> list = new ArrayList<>();
        //2、执行操作
        list = sqlSession.getMapper(IUserDao.class).selectAll();
        return list;
    }
    @Override
    public void deleteById(int id) {
        //2、执行操作
        sqlSession.getMapper(IUserDao.class).deleteById(id);
    }
    @Override
    public void updateUser(User user) {
        //2、执行操作
        sqlSession.getMapper(IUserDao.class).updateUser(user);
    }
}
